package readers;

import com.svcon.jdbf.DBFReader;
import com.svcon.jdbf.JDBFException;
import org.apache.log4j.Logger;

import java.util.Arrays;
import java.util.List;

public class DBFRowReader implements RowReader {
    private final DBFReader reader;

    public DBFRowReader(DBFReader reader) {
        this.reader = reader;
    }

    public List<Object> read() throws JDBFException {
        return reader.hasNextRecord() ? Arrays.asList(reader.nextRecord()) : null;
    }

    public void printHeader(Logger log) {
        for(int i = 0; i < reader.getFieldCount(); i++) {
            log.debug("header field (" + i + "): " + reader.getField(i));
        }
    }

    public void close() throws Exception {
        reader.close();
    }
}
